﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KendoMvcUI.Common;
using KendoMvcUI.UI;

namespace KendoMvcUI.Core
{
    /// <summary>
    /// 需要绑定数据的控件，必须继承此类
    /// </summary>
    public class KendoBindingBase:KendoUIControlSettings
    {
        public KendoBindingBase(string kendoUIFunctionName)
            : base(kendoUIFunctionName)
        {
        }
        [PropertySetting(IsIngoreForJavaScript=true)]
        public Action<DataSourceSettings> DataSource { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [PropertySetting(IsIngoreForJavaScript=true)]
        public string DataTextField { get; set; }
        public override string ToJsSettings()
        {
            string jsString = base.ToJsSettings();
            if(!jsString.EndsWith(",")&&!jsString.IsNullOrWhiteSpace())
                jsString+=",";
            if (DataSource != null)
            {
                var dataSource = new DataSourceSettings();
                DataSource(dataSource);
                jsString += dataSource.ToString() + ",";
            }
                

            if (!DataTextField.IsNullOrWhiteSpace())
                jsString += "dataTextField:'{0}',".Formator(DataTextField);

            return jsString;
        }
    }
}
